package com.cskaoyan.service;

import com.cskaoyan.bean.MarketGoodsAttribute;
import com.cskaoyan.bean.MarketGoodsAttributeExample;
import com.cskaoyan.bean.MarketGoodsExample;
import com.cskaoyan.mapper.MarketGoodsAttributeMapper;
import com.cskaoyan.util.MyBatisUtil;
import com.cskaoyan.util.TransactionUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author Ramsey
 * @date 2023年05月30日 13:47
 */
public class GoodsAttributeServiceimpl implements GoodsAttributeService {
    @Override
    public void add(MarketGoodsAttribute attribute) {
        SqlSession sqlSession = TransactionUtil.getSqlSession();
        MarketGoodsAttributeMapper mapper = sqlSession.getMapper(MarketGoodsAttributeMapper.class);
        mapper.insertSelective(attribute);
    }

    @Override
    public List<MarketGoodsAttribute> selectByGoodsId(Integer id) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        MarketGoodsAttributeMapper mapper = sqlSession.getMapper(MarketGoodsAttributeMapper.class);
        MarketGoodsAttributeExample example = new MarketGoodsAttributeExample();
        MarketGoodsAttributeExample.Criteria criteria = example.createCriteria();
        criteria.andIdEqualTo(id);
        List<MarketGoodsAttribute> marketGoodsAttributes = mapper.selectByExample(example);
        return marketGoodsAttributes;
    }

    @Override
    public void update(MarketGoodsAttribute attribute) {
        SqlSession sqlSession = TransactionUtil.getSqlSession();
        MarketGoodsAttributeMapper mapper = sqlSession.getMapper(MarketGoodsAttributeMapper.class);
        mapper.updateByPrimaryKeySelective(attribute);
    }
}
